public class num671 {
    //找到特殊二叉树中第二小的值
    public int findSecondMinimumValue(TreeNode root) {
       return findLeftAndRightOfMin(root,root.val);
    }

    private int findLeftAndRightOfMin(TreeNode root, int val) {
        if(root == null) {
            return -1;
        }
        if(root.val > val){
            return root.val;
        }
        int left = findLeftAndRightOfMin(root.left,val);
        int right = findLeftAndRightOfMin(root.right,val);
        if(left > root.val && right > root.val) {
            return Math.min(left,right);
        }
        return Math.max(left,right);
    }
}
